package com.lzp.utilsexample.main

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.base.BaseFragment
import com.dialog.MultipleDialog
import com.lzp.utilsexample.R
import com.lzp.utilsexample.dialog.DialogDemoActivity
import com.utils.ToastUtils
import com.utils.permission.PermissionConstant
import com.utils.permission.PermissionListener
import com.utils.permission.PermissionUtils
import kotlinx.android.synthetic.main.utils_example_fragment.*

/**
 * @describe:
 * @Author: lixiaopeng
 * @Date: 2020/3/24
 */
class UtilsExampleFragment : BaseFragment(), View.OnClickListener {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.utils_example_fragment, null)
    }

    override fun setListener() {
        super.setListener()
        dialogTv.setOnClickListener(this)
        permission.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        var intent:Intent? = null
        when (v?.id) {
            R.id.dialogTv -> {
                intent = Intent(activity,DialogDemoActivity::class.java)
                startActivity(intent)
            }
            R.id.permission->{
                requestPermission()
            }
        }
    }

    private fun requestPermission(){
        PermissionUtils.getPermission(activity, PermissionConstant.EXTERNAL_STORAGE_GROUP, object : PermissionListener {
            override fun onGranted() {
                ToastUtils.toastText(activity, "权限获取成功")
            }

            override fun onDenied(deniedPermissions: MutableList<String>?, neverTips: Boolean) {
                ToastUtils.toastText(activity,"onDenied: 权限获取失败" + if (neverTips) "且用户选择不再提示" else "")
            }
        })

    }
}